package com.lzy.mall.order.aop;

import com.lzy.mall.order.annotation.LzyRole;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lzy
 * @date 2021/9/30 15:39
 */
@Component
@Aspect
@Slf4j
public class RoleAspect {
    @Pointcut("@annotation(com.lzy.mall.order.annotation.LzyRole)")
    private void pointcut(){}

    @Before("pointcut() && @annotation(role)")
    public void advice(JoinPoint joinPoint, LzyRole role) {
        List<String> list = new ArrayList<>();
        list.add("admin");
        list.add("t0");
        list.add("t1");
        String value = role.value();
        if (list.contains(value)){
            System.out.println("拥有权限：" + value);
        }else {
            System.out.println("你的权限不够！！！");
        }
    }
}
